import time

from ui_yk.Page.Page import Page
import pytest
from selenium import webdriver
from selenium.webdriver.common.by import By
import unittest

class Testcase(unittest.TestCase):
    @pytest.fixture(scope='function')
    def page(self):
        # 指定浏览器
        browser = webdriver.Chrome()
        # 窗口最大化
        browser.maximize_window()
        try:
            # 打开网址
            browser.get('https://www.sogou.com/')
            # 搜索框是否存在
            dy = browser.find_element(By.ID, 'query').is_enabled()
            print(dy)
            # 返回
            yield browser
        except Exception as e:
            print(e)
        finally:
            # 退出浏览器
            if browser:
                browser.quit()

    def setUp(self):
        self.driver = webdriver.Chrome()
        self.driver.maximize_window()
        self.driver.get('https://www.sogou.com/')

    def tearDown(self):
        time.sleep(5)
        self.driver.quit()

    def test_01(self):
        po = Page(self.driver)
        po.send_search()
        po.click_search()
        self.driver.implicitly_wait(3)
        # dy = self.driver.find_element(By.XPATH,'/html/body/div[3]/div[2]/div[1]/div[4]/div/div[1]/div[1]/a/h3/span').text
        # assert '自动化测试' == dy
        title = self.driver.find_elements(By.TAG_NAME,'span')
        print(title)

    def test_02(self):
        po = Page(self.driver)
        po.send_search()
        po.click_search()
        po.click_two()
        dy = self.driver.find_element(By.XPATH,'/html/body/div[3]/div[2]/div[1]/div[4]/div/div[1]/div[1]/a/h3/span').text
        assert '自动化测试' == dy
        title = self.driver.find_elements(By.TAG_NAME, 'span')
        print(title)